<template>
  <section>
    <van-sticky>
      <PageHeader title="我的服务" />
    </van-sticky>

    <van-list
      class="mt10"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="requestData">
      <div class="flex flex-col bg-color-white font-common mb10"
           v-for="(item, index) in dataList"
           :key="index"
            @click="$router.push({name: 'MyServiceDetail', query: {order_sn: item.order.order_sn}})">
        <div class="flex flex-row flex-left font-big strong pd10">套餐：{{item.package.name}}</div>
        <div class="flex flex-row pd10">
          <div class="flex flex-row flex-left flex-1">订单状态：{{item.order.order_status_label}}</div>
          <div class="flex flex-row flex-left flex-1">付款状态：{{item.order.pay_status_label}}</div>
        </div>
        <div class="flex flex-row flex-left pd10">下单时间：{{item.order.create_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
        <div class="flex flex-row flex-left pd10" v-if="item.order.pay_time > 0">付款时间：{{item.order.pay_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}</div>
      </div>
    </van-list>

  </section>
</template>

<script>
  import PageHeader from "../../componets/PageHeader";
  import {servicePackageOrderListsUri} from "../../../common/api";

  export default {
    components: {
      PageHeader
    },
    data() {
      return {
        currentPage: 1,
        lastPage: 0,
        total: 0,
        pageSize: 10,
        loading: false,
        finished: false,
        dataList: []
      }
    },
    methods: {
      requestData() {
        const that = this;
        this.loading = true;
        const url = servicePackageOrderListsUri + '?page_size=' + that.pageSize + '&page=' + that.currentPage;
        this.$http.get(url).then(response => {
          let {code, msg, data} = response.body
          if (code != 0) {
            that.toast(msg);
          } else {
            that.loading = false;
            if (that.currentPage >= data.last_page) {
              that.finished = true;
            }
            that.currentPage = that.currentPage + 1;
            for (let i = 0; i < data.data.length; i++) {
              that.dataList.push(data.data[i]);
            }
            that.total = data.total;
            that.lastPage = data.last_page;
          }
        }, response => {
          // error callback
        })
      }
    },
    mounted: function () {

    }
  }
</script>

<style scoped>

</style>
